<template>
  <div class="app-container">
    <el-form ref="form" :model="messageInfo" label-width="80px">
      <el-form-item label="用户昵称">
        <el-input v-model="messageInfo.userName" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="留言信息">
        <el-input v-model="messageInfo.messageText"></el-input>
      </el-form-item>
      <el-form-item label="留言类型">
        <el-select v-model="messageInfo.msgType" placeholder="请选择留言类型" >
          <el-option label="文章评论" value="1"></el-option>
          <el-option label="弹幕评论" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addUserInfo">添加信息</el-button>
        <el-button type="primary" @click="addUserInfo">修改信息</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
 import messageInfoApi from "@/api/message/messageInfo";
  
  export default {
    data() {
      return {
        messageInfo: {
          userName: '',
          msgType: '',
          messageText: ''
        },
        dialogVisible: false
      }
      
    },
    created() {
       this.fetchData();
    },
    methods: {
    fetchData() {
       let roleId= this.$route.params.id == ':id' ? 0: this.$route.params.id
       messageInfoApi.show(roleId).then(result => {
          const messageInfo = result.data
          this.messageInfo = messageInfo
        })
      },
      addUserInfo() {
        if(this.$route.params.id == ':id'){
        messageInfoApi.save(this.messageInfo).then((response)=>{
        this.$message.success(response.message || '操作成功')
        this.dialogVisible = false
        this.fetchData()
        })}
        else{
        messageInfoApi.update(this.messageInfo).then((response)=>{
        this.$message.success(response.message || '操作成功')
        this.dialogVisible = false
        this.fetchData()
        })
        }
      },
    }
    
  }
</script>